package com.example.controller;

import com.example.entity.Staffs;
import com.example.result.CommonResult;
import com.example.service.StaffsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @project: smart-property
 * @description: 员工管理 controller 层
 * @author: cjq
 * @create: 2022-11-16 15:50
 **/
@RestController
@RequestMapping("/staffs")
public class StaffsController {
    @Autowired
    StaffsService staffsService;

    /**
     * 判断员工姓名是否有重复
     * @param staffName
     * @return
     */
    @GetMapping("/listStaffName")
    public CommonResult listStaffName(String staffName){
        return CommonResult.ok(staffsService.listStaffName(staffName));
    }

    /**
     * 添加/修改个人信息
     * @param file
     * @param staffs
     * @return
     */
    @PostMapping("/saveStaffsInfo")
    public CommonResult saveStaffsInfo(MultipartFile file, Staffs staffs){
        return CommonResult.ok(staffsService.saveStaffsInfo(file,staffs));
    }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @GetMapping("/listStaffsInfo")
    public CommonResult listStaffsInfo(Integer id){
        return CommonResult.ok(staffsService.listStaffsInfo(id));
    }

    /**
     * 重置密码为123456
     * @param id
     * @return
     */
    @DeleteMapping("/resetPassword")
    public CommonResult resetPassword(Integer id){
        return CommonResult.ok(staffsService.resetPassword(id));
    }
}
